#pragma once

#include "TcpServer.h"
#include <string>
namespace muduo{
    class EchoServer{
    private:
        TcpServer _server;
    private:
        // 只进行回显消息
        void message_callback(const PtrConnection& con,Buffer* buf){
            con->Send(buf->GetReadIndex(),buf->EnableReadSize());
            buf->MoveReadidx(buf->EnableReadSize());
        }
        void connect_callback(const PtrConnection& con){
            infolog<<con->Id()<<": Connected";
        }
        void close_callback(const PtrConnection& con){
            infolog<<con->Id()<<": Closed";
        }
    public:
        EchoServer(int port):_server(port){
            _server.SetPoolNum(12);
            _server.SetInactiveRelease(3);
            _server.SetConnectedCallback(bind(&EchoServer::connect_callback,this,std::placeholders::_1));
            _server.SetMessageCallback(bind(&EchoServer::message_callback,this,std::placeholders::_1,std::placeholders::_2));
            _server.SetCloseCallback(bind(&EchoServer::connect_callback,this,std::placeholders::_1));
        }
        void start(){
            _server.start();
        }
    };
}